package com.ihr360.payroll.model.dto.attendance.rule.overtime;

import com.ihr360.commons.model.entity.NumberIdWithTime;
import com.ihr360.payroll.model.base.IBaseAttendanceRule;
import com.ihr360.payroll.model.code.CycleStandard;
import com.ihr360.payroll.model.dto.salary.meta.SalaryField;
import com.ihr360.payroll.type.BasementType;
import lombok.Getter;
import lombok.Setter;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import java.util.ArrayList;
import java.util.List;

/**
 * 综合公式加班计薪规则
 */
@Entity
@Setter
@Getter
public class SyntheticalOverTimeRule extends NumberIdWithTime<Long> implements IBaseAttendanceRule {
    @OneToOne
    private OvertimeRule rule;

    /**
     * 周期工时数
     */
    private Integer workCount;

    /**
     * 综合扣款规则
     */
    @OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, mappedBy = "rule")
    private SyntheticalDebitRule debitRule;

    /**
     * 工时周期标准
     */
    @ManyToOne(fetch = FetchType.LAZY)
    private CycleStandard standard;

    /**
     * 引用基数 (是否可以考虑使用公式替换)
     */
    @ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.REMOVE)
    private List<SalaryField> referenceFields = new ArrayList<>();

    /**
     * 固定基数
     */
    private Double fixedBase;

    /**
     * 基数比例
     */
    @Column(length = 8)
    private Double baseRatio = 100.0;

    /**
     * 计算比例
     */
    @Column(length = 8)
    private Double numOpRatio = 100.0;

    /**
     * 节假日比例
     */
    private Double holidayRatio;

    @Column(length = 10)
    @Enumerated(value = EnumType.STRING)
    private BasementType basementType;

    public SyntheticalOverTimeRule() {
    }

    @Override
    public Double getFixedBase() {
        return fixedBase;
    }

    @Override
    public Double getBaseRatio() {
        return baseRatio;
    }

    @Override
    public Double getNumOpRatio() {
        return numOpRatio;
    }

    @Override
    public List<SalaryField> getReferenceFields() {
        return referenceFields;
    }

    @Override
    public BasementType getBasementType() {
        return basementType;
    }
}